home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Microsoft / Expression Blend / Blend.en.msi / Sparkle.AStudio.DelegateCommand.cs.en < prev    next >
Encoding:
Text File  |  2007-01-30  |  1.2 KB  |  56 lines

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Input;
  5.  
  6. namespace UntitledProject1
  7. {
  8.     public sealed class DelegateCommand : ICommand
  9.     {
  10.         public delegate void SimpleEventHandler();
  11.  
  12.         private SimpleEventHandler handler;
  13.  
  14.         private bool isEnabled = true;
  15.  
  16.         public DelegateCommand(SimpleEventHandler handler)
  17.         {
  18.             this.handler = handler;
  19.         }
  20.  
  21.         #region ICommand implementation
  22.  
  23.         void ICommand.Execute(object arg)
  24.         {
  25.             this.handler();
  26.         }
  27.  
  28.         bool ICommand.CanExecute(object arg)
  29.         {
  30.             return this.IsEnabled;
  31.         }
  32.  
  33.         public event EventHandler CanExecuteChanged;
  34.  
  35.         #endregion
  36.  
  37.         public bool IsEnabled
  38.         {
  39.             get { return this.isEnabled; }
  40.             set
  41.             {
  42.                 this.isEnabled = value;
  43.                 this.OnCanExecuteChanged();
  44.             }
  45.         }
  46.  
  47.         private void OnCanExecuteChanged()
  48.         {
  49.             if (this.CanExecuteChanged != null)
  50.             {
  51.                 this.CanExecuteChanged(this, EventArgs.Empty);
  52.             }
  53.         }
  54.     }
  55. }
  56.